I got the data from a Kaggle website ( https://www.kaggle.com/NUFORC/ufo-sightings ) It contains a dataset of 80332 ufo sightings across the world collected over the last century.
ufos_raw <- read_csv("ufos-scrubbed.csv") %>%
filter(country == "us")
head(ufos_raw) %>% kable("html")
| datetime | city | state | country | shape | duration (seconds) | duration (hours/min) | comments | date posted | latitude | longitude |
|---|---|---|---|---|---|---|---|---|---|---|
| 10/10/1949 20:30 | san marcos | tx | us | cylinder | 2700 | 45 minutes | This event took place in early fall around 1949-50. It occurred after a Boy Scout meeting in the Baptist Church. The Baptist Church sit | 4/27/2004 | 29.88306 | -97.94111 |
| 10/10/1956 21:00 | edna | tx | us | circle | 20 | 1/2 hour | My older brother and twin sister were leaving the only Edna theater at about 9 PM,…we had our bikes and I took a different route home | 1/17/2004 | 28.97833 | -96.64583 |
| 10/10/1960 20:00 | kaneohe | hi | us | light | 900 | 15 minutes | AS a Marine 1st Lt. flying an FJ4B fighter/attack aircraft on a solo night exercise, I was at 50ꯠ' in a "clean" aircraft (no ordinan | 1/22/2004 | 21.41806 | -157.80361 |
| 10/10/1961 19:00 | bristol | tn | us | sphere | 300 | 5 minutes | My father is now 89 my brother 52 the girl with us now 51 myself 49 and the other fellow which worked with my father if he's still livi | 4/27/2007 | 36.59500 | -82.18889 |
| 10/10/1965 23:45 | norwalk | ct | us | disk | 1200 | 20 minutes | A bright orange color changing to reddish color disk/saucer was observed hovering above power transmission lines. | 10/2/1999 | 41.11750 | -73.40833 |
| 10/10/1966 20:00 | pell city | al | us | disk | 180 | 3 minutes | Strobe Lighted disk shape object observed close, at low speeds, and low altitude in Oct 1966 in Pell City Alabama | 3/19/2009 | 33.58611 | -86.28611 |
-Text wrap comments column so that hover visualization shows multi-line output
-Coerce datetime into date format and extract Year & Year/Month as a new columns.
#Data transformation
ufos_raw$comments <- str_wrap(ufos_raw$comments, 50)
ufos_raw$year <-format(as.Date(ufos_raw$datetime,format="%m/%d/%Y"),"%Y")
ufos_raw$month <-format(as.Date(ufos_raw$datetime,format="%m/%d/%Y"),"%Y/%m")
#Select just the data needed
ufos <- ufos_raw %>%
filter(year >= '2000') %>%
select(c(datetime, latitude, longitude, month, comments, state, city, year, shape))
head(ufos) %>% kable("html")
| datetime | latitude | longitude | month | comments | state | city | year | shape |
|---|---|---|---|---|---|---|---|---|
| 10/10/2000 03:00 | 37.72417 | -89.86111 | 2000/10 | The craft was big, orange, and oval shaped. | mo | perryville | 2000 | oval |
| 10/10/2000 06:15 | 26.52500 | -80.06667 | 2000/10 | Unusual light formation moving extremely fast across the sky. | fl | boynton beach | 2000 | other |
| 10/10/2000 20:30 | 38.12667 | -92.08444 | 2000/10 | 3 bright golden lights moving independently above the tree line flaring and fading intermittently for approx. 15 min. | mo | brinktown | 2000 | light |
| 10/10/2000 21:30 | 38.99889 | -84.62667 | 2000/10 | Two objects traveling side by side pass over, as one begins to zig, zag it's path. | ky | florence | 2000 | light |
| 10/10/2000 21:30 | 47.60639 | -122.33083 | 2000/10 | Dark object in the shape of a (4) after dusk in West Seattle | wa | seattle (west) | 2000 | unknown |
| 10/10/2000 22:00 | 47.54056 | -122.63500 | 2000/10 | One night my window started to flash | wa | port orchard | 2000 | diamond |
ufos %>%
plot_mapbox(frame = ~month) %>% #frame creates animation
layout(
mapbox = list(
style = "dark", #changes map style
zoom = 2.4,
center = list(lat = 37, lon = -95) #centers on USA
)
) %>%
add_markers(
x = ~longitude,
y = ~latitude,
marker = list(size = 3, color = "#FFFFCC", opacity = 0.4), #creates glyph aesthetic
) %>%
animation_opts(100) #sets the number of milliseconds per frame
ufos1 <- ufos %>%
plot_mapbox() %>%
layout(
mapbox = list(
style = "dark",
zoom = 2.4,
center = list(lat = 37, lon = -95)
)
) %>%
add_markers(
x = ~longitude,
y = ~latitude,
marker = list(size = 2, color = "#FFFFCC", opacity = 0.2),
text = ~paste("<b>Date/Time:</b>", datetime,"<br><b>Report:</b>", comments, "<br><b>City/State:</b>", city, ",", state),
textposition = "auto",
hoverlabel = list(align = "left"),
hoverinfo = "text"
)
ufos1